﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DeployGames.TweenEngine.equations
{
    public abstract class Bounce : TweenEquation
    {
        public static BounceIN IN = new BounceIN();
        public static BounceOUT OUT = new BounceOUT();
        public static BounceINOUT INOUT = new BounceINOUT();

        #region BounceIN
        public class BounceIN : Bounce
        {
            public override float compute(float t)
            {
                return 1 - OUT.compute(1 - t);
            }

            public override string ToString()
            {
                return "Bounce.IN";
            }
        }
        #endregion

        #region BounceOUT
        public class BounceOUT : Bounce
        {
            public override float compute(float t)
            {
                if (t < (1 / 2.75))
                {
                    return 7.5625f * t * t;
                }
                else if (t < (2 / 2.75))
                {
                    return 7.5625f * (t -= (1.5f / 2.75f)) * t + .75f;
                }
                else if (t < (2.5 / 2.75))
                {
                    return 7.5625f * (t -= (2.25f / 2.75f)) * t + .9375f;
                }
                else
                {
                    return 7.5625f * (t -= (2.625f / 2.75f)) * t + .984375f;
                }
            }

            public override string ToString()
            {
                return "Bounce.OUT";
            }
        }
        #endregion

        #region BounceINOUT
        public class BounceINOUT : Bounce
        {

            public override float compute(float t)
            {
                if (t < 0.5f) return IN.compute(t * 2) * .5f;
                else return OUT.compute(t * 2 - 1) * .5f + 0.5f;
            }

            public override string ToString()
            {
                return "Bounce.INOUT";
            }
        }
        #endregion
    }
}
